<?php

class Mnick extends CI_Model {
	
	public $table = 'tbl_nicks';
	public $pri_key="nick_id";
	public $table_cate = 'news_cate';
	public $pri_key_cate="news_cate_id";

	function __construct()

	{

		parent::__construct();
		
	}
	public function del_item($id)
	{
		$this->db->where($this->pri_key, $id);
		$this->db->delete($this->table); 
			
	}
	function get_promotion()
	{
		$this->db->limit(5);
		$this->db->where("news_cate =",2);
		$this->db->where("news_check =",1);
		$this->db->order_by($this->pri_key,"DESC");
		$query = $this->db->get($this->table);
		
		if($query->num_rows() >0)
		{
			return $query->result_array();
		}
		return false;
		
		
	}
	function last_news()
	{
		$this->db->limit(5);
		$this->db->order_by($this->pri_key,"DESC");
		if($this->db->count_all($this->table) >0)
			{
				return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	function count_news_by_cate($id)
	{
		
		$this->db->join('news_cate', 'news_cate.news_cate_id = news.news_cate');
		$this->db->where($this->pri_key_cate." =",$id);
		$this->db->order_by($this->pri_key,"DESC");
		$query = $this->db->get($this->table);
		return $query->num_rows();
		
	}
	function list_news_form_cate($num,$off,$id)
	{
		//$id = $this->uri->segment(3);
		$this->db->limit($off,$num);
		$this->db->join('news_cate', 'news_cate.news_cate_id = news.news_cate');
		$this->db->where($this->pri_key_cate." =",$id);
		$this->db->order_by($this->pri_key,"DESC");
		$query = $this->db->get($this->table);
		if($query->num_rows() >0)
			{
				return $query->result_array();
			}
		return false;
	}
		
	//*********** News **************//
	function list_data($num,$off)
	{
	$this->db->limit($off,$num);
	//	$this->db->join('news_cate', 'news_cate.news_cate_id = news.news_cate');
		$this->db->order_by($this->pri_key,"DESC");
		if($this->db->count_all($this->table) >0)
			{
				return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	
	//******* insert news **********//
	
	function insert_data($data)
	{
		if($this->db->insert($this->table,$data))
			return true;
		return false;
	
	}
	public function get_cate()
	{

		$query = $this->db->get('news_cate');
		return $query->result_array();

	}
	public function info_from_id($id,$table)
	{
		if($table == 'tbl_nicks')
		{
			$pri_key=$this->pri_key;
		}
		else
			$pri_key=$this->pri_key_cate;
		if(is_numeric($id) && $id !="")
		{
			$this->db->where($pri_key.' =',$id);
			return $this->db->get($table)->result_array();
		}
		else
			return false;
	}
	
	//********* update **************///
		function update_data($data,$id)
	{
		if(is_numeric($id) && $id !='')
		{
			$this->db->where($this->pri_key,$id);
			if($this->db->update($this->table,$data))
				return true;
			return false;
			
		}
		return false;
	}
	


	function delete()

	{

		if (isset($_POST['checkbox1']))

		{

			foreach($_POST['checkbox1'] as $id) {

				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
				//$this->db->query($sql);

			}			

		}

	}
	/*********************** News Category ******************////
	
	function list_cate($num,$off)
	{
	$this->db->limit($off,$num);
		$this->db->order_by($this->table_cate.".".$this->pri_key_cate, "desc"); 
		if($this->db->count_all($this->table_cate) >0)
			{
				return $this->db->get($this->table_cate)->result_array();
			}
		return false;
	}
	
	// dem so record 
	function count_all($table)
	{
		return $this->db->count_all_results($table);
	}

	
	// insert  News category
	function insert_cate($data)
	{
		if($this->db->insert($this->table_cate,$data))
			return true;
		return false;
	
	}
	// update News category
	function update_cate($data,$id)
	{
		if(is_numeric($id) && $id !='')
		{
			$this->db->where($this->pri_key_cate,$id);
			if($this->db->update($this->table_cate,$data))
				return true;
			return false;
			
		}
		return false;
	}


	function cate_delete()

	{

		if (isset($_POST['select_id']))

		{

			foreach($_POST['select_id'] as $id)
			{

		
				$this->db->where($this->pri_key_cate, $id);
				$this->db->delete($this->table_cate); 
				

			}			

		}

	}

/*** index  **///

public function get_data($lang="")
	{
		
	
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
				$this->db->where('nick_status =',1);
			$this->db->order_by($this->pri_key,"DESC");
	
	return $this->db->get($this->table)->result_array();
			}
		return false;
	}

}//end model class





/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>